package com.example.test.comutil;

import android.content.Context;
import android.text.TextUtils;

import com.example.test.R;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {
    public static int date_format = 7, time_format = 2;
    public static String automaticDate;//当前显示的年月日
    public static String automaticTime;//当前显示的时分秒

    public static String[] date_choice_cn = {LeoUtils.getApplication().getString(R.string.no2), "yyyy年MM月dd日 ", "yyyy年MM月 ", "MM月dd日 ", "yyyy-MM-dd ", "yyyy-MM ", "MM-dd ", "yyyy/MM/dd ", "yyyy/MM ", "MM/dd ", "MM-dd-yyyy ", "dd-MM-yyyy ", "dd/MM/yyyy "};
    public static String[] date_choice_en = {LeoUtils.getApplication().getString(R.string.no2), "yyyy MM dd ", "yyyy MM ", "MM dd ", "yyyy-MM-dd ", "yyyy-MM ", "MM-dd ", "yyyy/MM/dd ", "MM/yyyy ", "dd/MM ", "MM-dd-yyyy ", "dd-MM-yyyy ", "dd/MM/yyyy "};
    public static String[] date_choice = date_choice_cn;
    public static String[] date_choiceTW = {LeoUtils.getApplication().getString(R.string.no2), "yyyy MM dd ", "yyyy MM ", "MM dd ", "yyyy-MM-dd ", "yyyy-MM ", "MM-dd ", "yyyy/MM/dd ", "yyyy/MM ", "MM/dd "};
    public static String[] time_choiceTW = {LeoUtils.getApplication().getString(R.string.no2), "HH:mm:ss ", "HH:mm  ", "mm:ss  "};
    public static String[] GetDate_choice(Context context) {
        if (MultiLanguageUtils.isEnglish(context)) {
            date_choice = date_choice_en;
        } else {
            date_choice = date_choice_cn;
        }
        return date_choice;
    }
    public static String GetSimpleDateFormat(Context _context){
        String current_format = "";
        try {
            Date curDate = new Date();
            //日期偏移量（以前用的   这个可能是日期偏移）
            String timedeviation = "0";
            //日期偏移量（后面加的   功能没有实现）
            String datedeviation = "0";
            SimpleDateFormat transformDate = null;
            if (!MultiLanguageUtils.isTaiwan(_context)) {
                transformDate = new SimpleDateFormat(GetDate_choice(_context)[date_format].replaceAll(_context.getString(R.string.no2), ""));
            } else {
                transformDate = new SimpleDateFormat(date_choiceTW[date_format].replaceAll(_context.getString(R.string.no2), ""));
            }

            SimpleDateFormat transformTime = null;
            if (!MultiLanguageUtils.isTaiwan(_context)) {
                transformTime = new SimpleDateFormat(GetDate_choice(_context)[time_format].replaceAll(_context.getString(R.string.no2), ""));
            } else {
                transformTime = new SimpleDateFormat(time_choiceTW[time_format].replaceAll(_context.getString(R.string.no2), ""));
            }
            if ((!TextUtils.isEmpty(datedeviation) && datedeviation.length() > 3) || (!TextUtils.isEmpty(timedeviation) && timedeviation.length() > 3)) {
                automaticDate = datedeviation;
                automaticTime = timedeviation;
                current_format = datedeviation + "  " + timedeviation;
            } else {
                String formatData = transformDate.format(curDate);
                String formatTime = transformTime.format(curDate);
                automaticDate = TextUtils.isEmpty(formatData) ? "" : formatData;
                automaticTime = TextUtils.isEmpty(formatTime) ? "" : formatTime;
                current_format = transformDate.format(curDate) + transformTime.format(curDate);
            }
        }catch(Exception e){
            LogUtils.e("DateUtils","GetSimpleDateFormat e:"+e);
        }
        return current_format;

    }

}
